package com.shanzmoo.admin.web.store;

import com.shanzmoo.admin.domain.dto.BillOperateDto;
import com.shanzmoo.admin.domain.dto.BillSaveDto;
import com.shanzmoo.admin.domain.dto.BillUpdateDto;
import com.shanzmoo.admin.manager.store.StorePurchaseBillManager;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.db.store.entity.StorePurchaseBillEntity;
import com.shanzmoo.db.store.entity.query.StorePurchaseBillQuery;
import com.shanzmoo.db.store.entity.vo.StorePurchaseBillVO;
import com.shanzmoo.db.store.service.IStorePurchaseBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 仓库采购单 控制层
 *
 * @author xueqz 2021-03-07
 */
@Api(tags = "仓储-采购单")
@RestController
@RequestMapping("/store/purchase-bill")
public class StorePurchaseBillController {

    @Autowired
    private IStorePurchaseBillService storePurchaseBillService;
    @Autowired
    private StorePurchaseBillManager storePurchaseBillManager;

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<StorePurchaseBillVO>> pageList(@Valid @RequestBody StorePurchaseBillQuery query) {
        PageRespBase<StorePurchaseBillVO> pageList = storePurchaseBillManager.queryPage(query);
        return SHttpResponse.ok(pageList);
    }

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody BillSaveDto saveDto) {
        storePurchaseBillManager.add(saveDto);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public SHttpResponse<Boolean> deleteById(@RequestParam(value = "id") Integer id) {
        StorePurchaseBillEntity entity = new StorePurchaseBillEntity();
        entity.setId(id);
        storePurchaseBillService.updateById(entity);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody BillUpdateDto updateDto) {
        storePurchaseBillManager.update(updateDto);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "详情")
    @GetMapping("/detail")
    public SHttpResponse<StorePurchaseBillVO> detailById(@RequestParam(value = "id") Integer id) {
//        StorePurchaseBillVO storePurchaseBillVO = storePurchaseBillManager.detailById(id);
//        return SHttpResponse.ok(storePurchaseBillVO);
        return null;
    }

    @ApiOperation(value = "修改采购单据状态")
    @PostMapping("/operateBillStatus")
    public SHttpResponse<Boolean> operateBillStatus(@Valid @RequestBody BillOperateDto billOperateDto) {
        storePurchaseBillManager.operateBillStatus(billOperateDto);
        return SHttpResponse.ok(Boolean.TRUE);
    }
 }
